<template>
  <div :class="['GameViewVue']">
    <div class="view">
      <HeadView></HeadView>
      <div class="pageDiv">
        <router-view >

        </router-view>
      </div>
      <LiuYuanView></LiuYuanView>
      <AlertLayer></AlertLayer>
    </div>
  </div>

</template>


<style scoped>
.GameViewVue{
  position: relative;width: 100%;font-size: 14px;color: black;margin: auto;
}

.view{
  position: relative;width: 100%;margin: auto;

}
.headDiv{

}
.pageDiv{
  position: relative;
}

</style>

<script setup>
/*组件挂载完成后执行的函数；*/
import {ref,reactive,watch,computed,onBeforeUnmount, onMounted, onUnmounted} from "vue";
import { useStore} from 'vuex';
import {useRoute, useRouter} from 'vue-router';
import Enum from "@/js/Enum";

import HeadView from "@/views/components/HeadView";
import LiuYuanView from "@/views/components/LiuYuanView";
import AlertLayer from '@/views/layer/AlertLayer';

let store = useStore();
let router = useRouter();
let cls_id=winApp.getClsId();
let pagePath=ref(Enum.startPath);

onMounted(() => {

  console.log("GameViewVue onMounted PC端");
  //winApp.sendNotification(Enum.VIEW_LabelNoticeView,'我是PC端');
  routerDetermineHandler();

});


onBeforeUnmount(() => {
 // console.log('GameViewVue onBeforeUnmount');
})
onUnmounted(() => {
  //卸载组件实例后调用,调用此钩子时,组件实例的所有指令都被解除绑定,所有事件侦听器都被移除,所有子组件实例被卸载。
 // console.log("GameViewVue onUnmounted 卸载组件实例后  ");
});



let pagesState=computed(()=>{return store.state.pages;});
watch(pagesState,(newValue,oldValue)=>{
 // console.log("GameViewVue watch  pagesState ",newValue);
  if(routerData!=null){
    router.push({ path:store.state.pages,query:routerData});
  }else{
    router.push({ path:store.state.pages});
  }
  routerData=null;
});


let routerData=null;
let routerDetermineHandler=()=>{
  var url = window.location.href;
 // console.log("GameViewVue routerDetermineHandler 路由判断",url,router.options.routes);
  let urlary=url.split("#");
  let dataary=urlary[1].split("?");
  let pages=dataary[0];
 // console.log('截取',pages,dataary[1]);
  let toPages=Enum.startPath;
  let isOne=false;let queryDa={type:'init'};
  for(let i=0;i<router.options.routes.length;i++){
      if(pages==router.options.routes[i].path){
        toPages=router.options.routes[i].path;
        isOne=true;
        break;
      }
  }
  if(!isOne){
    for(let i=0;i<router.options.routes.length;i++){
      let children=(router.options.routes[i].children!=null?router.options.routes[i].children:[]);
      for(let k=0;k<children.length;k++){
        if(pages==children[k].path){
          toPages=router.options.routes[i].path;
          if(dataary.length>1){
            let ddd=dataary[1].split("&");
            console.log(dataary[1],ddd.length,ddd);
            queryDa={};
            for(let j=0;j<ddd.length;j++){
              let ddlist=ddd[j].split("=");
              let kkkk=ddlist[0]+'';
              queryDa[kkkk]=ddlist[1];
            }

          }

          break;
        }
      }
    }
  }
  //console.log('目标',toPages);
  routerData=queryDa;
  store.commit('updatePages',toPages);
 // router.push({ path:toPages,query:queryDa});
}



</script>



